package com.studiofortress.sf.structure.intersection;

import com.studiofortress.sf.structure.Actor;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;

/**
 * The centre of the Shape used is presumed to be the
 * centre and current location of the Actor. For example
 * the co-ordinate 0x0 in the shape is to be found in
 * the world at the actors x and y location.
 * @author Joseph Lenton
 * @version 03/08/2008
 */
 public class ShapeIntersection extends Intersection
 {
    private Shape shape;
    
    public ShapeIntersection(Actor actor)
    {
        this(actor,
            new Rectangle2D.Double(
                -actor.getWidth()/2, -actor.getHeight()/2,
                 actor.getWidth(),    actor.getHeight()));
    }
    
    public ShapeIntersection(Actor actor, Shape shape)
    {
        super(actor);
        
        if (shape == null) {
            throw new IllegalArgumentException("Shape cannot be null");
        }
        
        this.shape = shape;
    }
    
    public void setShape(Shape shape)
    {
        if (shape == null) {
            throw new IllegalArgumentException("Shape cannot be null");
        }
        
        this.shape = shape;
    }
    
    public Shape getShape()
    {
        return shape;
    }
    
    @Override
    public boolean isIntersection(Intersection other)
    {
        return other.isIntersectionToShape(this);
    }
     
    @Override
    protected boolean isIntersectionToPixel(PixelIntersection other)
    {
        return Intersection.intersectionPixelToShape(other.getActor(), getActor(), shape);
    }
    
    @Override
    protected boolean isIntersectionToBounds(BoundsIntersection other)
    {
        return Intersection.intersectionBoundsToShape(other.getActor(), getActor(), shape);
    }
    
    @Override
    protected boolean isIntersectionToImage(ImageIntersection other)
    {
        return Intersection.intersectionImageToShape(other.getActor(), getActor(), shape);
    }
    
    @Override
    protected boolean isIntersectionToShape(ShapeIntersection other)
    {
        return Intersection.intersectionShapeToShape(getActor(), shape, other.getActor(), other.getShape());
    }
}
 